<?php
/**
 * Created by PhpStorm.
 * User: luzy
 * Date: 2018/6/17
 * Time: 下午7:11
 */

class Qfgroup extends Base_Controller
{
    public function __construct()
    {
        $this->_page_size = 20;
        $this->_form_type = 'qf_group';
        $this->_list_where = array();
        $this->_action_list = array('EDIT');
        $this->_controller = 'admin/xfmba/qfgroup/';
        parent::__construct();
    }

    public function showList($page = 1)
    {
        $limit = $this->_page_size;
        $offset = ($page-1) * $limit;
        $pdata = $this->getPagination($this->_controller.'showList/');

        $res = $this->getList($offset,$limit);
        foreach ($res['list'] as &$row){
            $info = $this->db->select('name')->from('mod_qf_info')->where('id',$row['course'])->get()->row_array();
            $row['course']=$info['name'];
        }//处理表数据

        //有创建按钮
        $createbtn = $this->load->view('admin/form/createbtn',array('controller'=>site_url($this->_controller)),true);

        $data = array('headers'=>$res['headers'],'list'=>$res['list'],'pagination'=>$pdata['pagination'],'createbtn'=>$createbtn);
        $content = $this->load->view('admin/form/list',$data,true);

        echo $this->getAdminView($content);
    }

    public function update($id = 0)
    {
        $post = $this->input->post();
        if(empty($post)){
            $form = $this->updateBuildForm($id);
            $content = $this->load->view('admin/form/edit',array('controller'=>site_url($this->_controller),'form'=>$form),true);
            echo $this->getAdminView($content);
        }else{
            /******待编辑******/
            //filter post data
            $post['name']=trim($post['name']);
            $post['sort']=(int)trim($post['sort']);
            $post['num']=(int)trim($post['num']);
            $post['member']=str_replace('，',',',$post['member']);
            $post['member']=trim(trim($post['member']),',');
            $this->_update_data = $post;
            parent::update($id);
        }
    }
    public function afterupdate($pkey,$pkeyval){}

    public function create()
    {
        $post = $this->input->post();
        if(empty($post)){
            $form = $this->createBuildForm();
            $content = $this->load->view('admin/form/edit',array('controller'=>site_url($this->_controller),'form'=>$form),true);
            echo $this->getAdminView($content);
        }else{
            /******待编辑******/
            //filter post data
            $post['name']=trim($post['name']);
            $post['sort']=(int)trim($post['sort']);
            $post['num']=(int)trim($post['num']);
            $post['member']=str_replace('，',',',$post['member']);
            $post['member']=trim(trim($post['member']),',');
            $this->_create_data = $post;
            parent::create();
        }
    }

    public function aftercreate($pkeyval)
    {
        /*$pkey为主键，$pkeyval为主键值*/
    }

    public function delete($id = 0,$externalid = 0)
    {}

    public function afterdelete($pkey,$pkeyval){}
}